//
//  UIButton+Extension.swift
//  SinaWeibo
//
//  Created by celeste on 16/5/11.
//  Copyright © 2016年 celeste. All rights reserved.
//

import UIKit

extension UIButton {
    
    /// 便利构造函数
    
    convenience init(ld_title title: String?,
        fontSize: CGFloat = 17,
        titleColor: UIColor = UIColor.darkGrayColor(),
        imageName: String? = nil,
        backgroundImageName: String? = nil) {
            
            self.init()
            if let title = title {
                setTitle(title, forState: .Normal)
            }
            
            
            titleLabel?.font = UIFont.systemFontOfSize(fontSize)
            setTitleColor(titleColor, forState: .Normal)
            
            if let imageName = imageName {
                setImage(UIImage(named: imageName), forState: .Normal)
                setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
            }
            if let backgroundImageName = backgroundImageName {
                
                setBackgroundImage(UIImage(named: backgroundImageName), forState: .Normal)
                setBackgroundImage(UIImage(named: backgroundImageName + "_highlighted"), forState: .Highlighted)
            }
            sizeToFit()
    }
}